package com.tjetc._7date;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class _3NewDate {
    public static void main(String[] args) {
        /*
         1. LocalDate只包含⽇期，可以获取⽇期字段
         2. LocalTime只包含时间，可以获取时间字段
         3. LocalDateTime包含⽇期+时间，可以获取⽇期和时间字段
         */
        LocalDateTime now = LocalDateTime.now();
        System.out.println(now);
        System.out.println(now.getYear());
        System.out.println(now.getDayOfWeek());
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern
                ("yyyy-MM-dd HH:mm:ss");
        String format = dateTimeFormatter.format(now);
        System.out.println(format);
        LocalTime now1 = LocalTime.now();
        LocalDate now2 = LocalDate.now();
        LocalDateTime localDateTime = now.plusDays(10);
        System.out.println(localDateTime);
        // 时间戳和Date可以互相转换
        Instant now3 = Instant.now(); // 替代 Date
        System.out.println(now3);
        Date from = Date.from(now3);
        System.out.println(from);
        Instant instant = from.toInstant();
        System.out.println(instant);
    }
}
